<template>
    <div>
        <el-card class="!border-none" shadow="never">
            <el-alert type="warning" title="温馨提示：用户充值记录" :closable="false" show-icon></el-alert>
            <el-form ref="formRef" class="mb-[-16px] mt-[16px]" :model="queryParams" :inline="true">
                <el-form-item label="充值单号">
                    <el-input class="w-[280px]" v-model="queryParams.sn" placeholder="请输入充值单号" clearable
                        @keyup.enter="resetPage" />
                </el-form-item>
                <el-form-item label="用户信息">
                    <el-input class="w-[280px]" v-model="queryParams.user_info" placeholder="请输入用户编号/昵称/手机号" clearable
                        @keyup.enter="resetPage" />
                </el-form-item>
                <el-form-item label="支付方式">
                    <el-select class="w-[280px]" v-model="queryParams.pay_way">
                        <el-option label="全部" value />
                        <el-option label="微信支付" :value="2" />
                    </el-select>
                </el-form-item>
                <el-form-item label="支付状态">
                    <el-select class="w-[280px]" v-model="queryParams.pay_status">
                        <el-option label="全部" value />
                        <el-option label="未支付" :value="2" />
                        <el-option label="已支付" :value="1" />
                    </el-select>
                </el-form-item>
                <el-form-item label="下单时间">
                    <daterange-picker v-model:startTime="queryParams.start_time" v-model:endTime="queryParams.end_time" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                    <export-data class="ml-2.5" :fetch-fun="rechargeLists" :params="queryParams" :page-size="pager.size" />
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <el-table size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column label="用户信息" min-width="100">
                    <template #default="{ row }">
                        <div class="flex items-center">
                            <image-contain class="flex-none mr-2" :src="row.user.avatar" :width="40" :height="40"
                                preview-teleported fit="contain" />
                            {{ row.nickname }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="用户编号" prop="user_sn" min-width="190" />
                <el-table-column label="充值单号" prop="sn" min-width="190" />
                <el-table-column label="充值金额" prop="order_amount" min-width="100">
                </el-table-column>
                <el-table-column label="支付方式" prop="pay_way_text" min-width="100">
                    <template #default="{ row }">
                        <el-tag type="success" v-if="row.pay_way == 2">微信支付</el-tag>
                        <el-tag v-if="row.pay_way == 3">支付宝支付</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="支付状态" min-width="100">
                    <template #default="{ row }">
                        <el-tag v-if="row.pay_status == 1">已支付</el-tag>
                        <el-tag type="info" v-else>未支付</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="支付时间" prop="pay_time" min-width="180" />
                <el-table-column label="下单时间" prop="create_time" min-width="180" />

                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button v-if="row.pay_status == 1" v-perms="['finance:recharge:refund']" type="primary" link
                            :disabled="row.refund_status == 1" @click="handleRefund(row.id)">
                            退款
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>
<script lang="ts" setup name="articleLists">
import { rechargeLists, refund } from '@/api/finance'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
const queryParams = reactive({
    sn: '',
    user_info: '',
    pay_way: '',
    pay_status: '',
    start_time: '',
    end_time: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: rechargeLists,
    params: queryParams
})
const handleRefund = async (id: number) => {
    await feedback.confirm('确认重新退款？')
    await refund({
        recharge_id: id
    })
    getLists()
}

getLists()
</script>
